<template>
  <view>
      <uni-card v-for="project in projectList" :key="project.id" :title="project.name" :is-shadow="true" :extra="project.location + '>'" @click="switchProject(project)">
          <image mode='widthFix' :src="project.logo | coverFilter" style="width: 100%;"></image>
      </uni-card>
      <our-loading isFullScreen :active="loading" text="loading..." />
  </view>
</template>

<script>
import uniCard from '@/components/uni-card.vue'
import ourLoading from '@/components/our-loading/our-loading.vue'
import { mapGetters } from "vuex";
export default {
 data() {
    return {
        loading: false
    }
 },
 components: {
    uniCard,
    ourLoading
 },
 onShareAppMessage() {
    console.log("分享小程序");
  },
 mounted() {
     this.fetchProjectList()
 },
 computed: {
     ...mapGetters({
      projectList: 'projectList',
    }),
 },
 filters: {
     coverFilter(logo) {
         if (!logo) {
             return 'https://lnh-cloud-oss.oss-cn-chengdu.aliyuncs.com/840px (2).png'
         }
         return logo
     }
 },
 methods: {
    async fetchProjectList() {
        this.loading = true
        await this.$store.dispatch('project/getProjectList')
        this.loading = false
    },
    switchProject(project) {
        uni.setStorageSync('project', project) //存入缓存
        this.$store.dispatch('project/setProject', project)
        uni.switchTab({ url: '/pages/index/index' })
    }
 }
}
</script>

<style scoped lang="scss">

</style>
